<?php
session_start();

//$email = $_SESSION['email'];
$email = 'test@pdn.ac.lk';

$connetion = mysql_connect('localhost', 'root', 'thMOziJu') or die('Error in DB');
$db = mysql_select_db('supervisor_all_system') or die('Érror in selecting db');

$default_combo = "";

if ($_GET['drop']) {
	//Load the combo box, default value is last selected
	$sub_code = $_GET['Sub_Code'];
	$query = "delete from Supervises_Exam where Sub_Code = '$sub_code' and Email = '$email'";
	$result = mysql_query($query);
	
	$query = "select * from Supervises_Exam where Email = '$email'";
	$result = mysql_query($query);
	$list = array();
	while ($row = mysql_fetch_assoc($result)){
		$list[] = $row['Sub_Code'];
	}
	
	$combo_str = "";
	foreach($list as $v){
		$combo_str = $combo_str."<option value=\"".$v."\">".$v."</option>";
	}
	
}
else {
	$query = "select * from Supervises_Exam where Email = '$email'";
	$result = mysql_query($query);
	$list = array();
	while ($row = mysql_fetch_assoc($result)){
		$list[] = $row['Sub_Code'];
	}
	
	$combo_str = "";
	foreach($list as $v){
		$combo_str = $combo_str."<option value=\"".$v."\">".$v."</option>";
	}
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Search</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;	
}
</style>
</head>

<body>
<div class="container">
	<center><h1>Search Exams</h1></center>
	<div class="search_box">
	    <form action="drop.php" method="get">
            <select name="day" size="1">
                <?php echo $combo_str; ?>
            </select>
            <input type="submit" value="drop it" name="drop" />
	    </form>
    </div>
    
    <div class="search_box">
    	<center><a href="index.php">Back to Home</a></center>
    </div>
    
    <div style="padding:15px;"></div>
</div>

</body>
</html>